
class base_type:
    def __init__(self, struct=None):
        print(struct)
        if 'struct' in struct:
            s = struct['struct']
        else:
            s = struct
        for ss in s:
            # print(s[ss])
            if ss[0] != '@':
                print('tt1')
                self.__setattr__(ss, base_type(s[ss]))
            # print(s)
            elif '@arg' in s:
                for t in s['@arg']:
                    print(t)
                    if t == 'struct':
                        print('tt2')
                        self.__setattr__(t, base_type(s['@arg'][t]))
                    else:
                        print('add: ', t)
                        self.__setattr__(t + '_', s['@arg'][t])

            pass


struct_stream = {
    "struct": {
        "streaminfo": {
            "@key": "128ci128c32c256c128c256c",
            "@arg": {
                "transport_ip": "128c",
                "transport_port": "i",
                "platform_id": "128c",
                "channel_id": "32c",
                "channel_name": "256c",
                "nvr_type": "128c",
                "snap_pic": "256c"
            }
        }
    }
}
struct_stream_t = base_type(struct_stream)
for e in struct_stream_t.__dict__:
    if isinstance(struct_stream_t.__getattribute__(e), base_type):
        print(e)
        print(struct_stream_t.__getattribute__(e).__dict__)
        print(struct_stream_t.streaminfo.__dict__)
print(type(struct_stream_t))
